package cn.k.service.impl;

import cn.k.domain.MessageReply;
import cn.k.mapper.MessageReplyMapper;
import cn.k.qo.QueryObject;
import cn.k.service.IMessageReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MessageReplyServiceImpl implements IMessageReplyService {
    @Autowired
    private MessageReplyMapper messageReplyMapper;

    @Override
    @Transactional
    public void insert(MessageReply messageReply) {
         messageReplyMapper.insert(messageReply);
    }

    @Override
    public void delete(Long id) {
        messageReplyMapper.deleteByPrimaryKey(id);

    }

    @Override
    @Transactional
    public void update(MessageReply messageReply) {
        messageReplyMapper.updateByPrimaryKey(messageReply);

    }

    @Override
    public MessageReply get(Long id) {
        MessageReply messageReply = messageReplyMapper.selectByPrimaryKey(id);
        return messageReply;
    }

    @Override
    public List<MessageReply> selectAll() {
        List<MessageReply> messageReplys = messageReplyMapper.selectAll();
        return messageReplys;
    }


    @Override
    public List<MessageReply> selectForList(QueryObject qo) {
        List<MessageReply> messageReplys = messageReplyMapper.selectForList(qo);
        return messageReplys;
    }

    @Override
    public PageInfo<MessageReply> query(QueryObject qo) {
        //告诉插件我们查询第几页,每页多少条
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        //查询当前页数据
        List<MessageReply> messageReplys = messageReplyMapper.selectForList(qo);
        return new PageInfo<>(messageReplys);
    }

    @Override
    public List<MessageReply> selectByMessageId(Long id) {
        return messageReplyMapper.selectByMessageId(id);
    }
}
